<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: red;
    }
  </style>
</head>

<body>
  <div class="box"></div>
  <input class="inp" type="text" placeholder="请输入姓名">

  <script>
    const box = document.querySelector('.box')
    const inp = document.querySelector('.inp')

    // 鼠标移入 mouseenter
    box.addEventListener('mouseenter', function () {
      this.style.backgroundColor = 'green'
    })
    // 鼠标移出 mouseleave
    box.addEventListener('mouseleave', function () {
      this.style.backgroundColor = 'red'
    })

    // 获取焦点 focus
    inp.addEventListener('focus', function () {
      this.style.width = '200px'
    })
    // 失去焦点 blur
    inp.addEventListener('blur', function () {
      this.style.width = '100px'
    })

    // 监听键盘按下和抬起
    inp.addEventListener('keydown', function (e) {
      console.log(e.key); // 键盘按的内容
      if (e.key == 'Entry') {
        console.log('你按下了回车')
      }
    })

    // 表单value值变化触发
    inp.addEventListener('input', function () {
      console.log(this.value);
    })

    // 表单value值变化触发(箭头函数)
    inp.addEventListener('input', (e) => {
      console.log(e.target.value);
    })
  </script>
</body>

</html>